<?php
/* Template Name: Larch Theme
 * 
 * Author: R. Dan and Co. Dev 
 * 
 */

function _list_child_page($atts){
	extract(  
		shortcode_atts( array(
			'page_title'=>'',
			'page_id'=>0,
			'exclude_ids'=>''
		),
		$atts ));
	if($page_id == 0){
		$page = get_page_by_title($page_title);
		$page_id = $page->ID;
	}
	$children_pages = get_pages(array(
		'child_of'=>$page_id,
		'exclude'=>$excludes_ids,
	)); ?>
	<div class="shortcode-entry">
<?php
	foreach($children_pages as $child_page){
		if(!$child_page->post_excerpt) return;
		$content = apply_filters('the_content', $child_page->post_excerpt);
?>
		<h3><a href = "<?php echo get_page_link($child_page->ID); ?>"><?php echo $child_page->post_title; ?></a></h3>
		<p class="shortcode-content"><?php echo $content; ?></p>
<?php } ?>
	</div>
<?php
}
add_action('child_pages','_list_child_page');
function list_single_post(){
	
}
add_action('show_single_post','list_single_post');
function thumbnail_only(){
	
}
add_action('thumbnail_of','thumbnail_only');
	/**
	 * List products in a category shortcode
	 *
	 * @access public
	 * @param array $atts
	 * @return string
	 */
function wc_product_category( $atts ) {
		global $woocommerce_loop;

		if ( empty( $atts ) ) return '';

		extract( shortcode_atts( array(
			'per_page' 		=> '12',
			'columns' 		=> '4',
			'orderby'   	=> 'title',
			'order'     	=> 'desc',
			'category'		=> '',
			'operator'      => 'IN' // Possible values are 'IN', 'NOT IN', 'AND'.
			), $atts ) );

		if ( ! $category ) return '';

		// Default ordering args
		$ordering_args = WC()->query->get_catalog_ordering_args( $orderby, $order );

		$args = array(
			'post_type'				=> 'product',
			'post_status' 			=> 'publish',
			'ignore_sticky_posts'	=> 1,
			'orderby' 				=> $ordering_args['orderby'],
			'order' 				=> $ordering_args['order'],
			'posts_per_page' 		=> $per_page,
			'meta_query' 			=> array(
				array(
					'key' 			=> '_visibility',
					'value' 		=> array('catalog', 'visible'),
					'compare' 		=> 'IN'
				)
			),
			'tax_query' 			=> array(
				array(
					'taxonomy' 		=> 'product_cat',
					'terms' 		=> array( esc_attr( $category ) ),
					'field' 		=> 'slug',
					'operator' 		=> $operator
				)
			)
		);

		if ( isset( $ordering_args['meta_key'] ) ) {
			$args['meta_key'] = $ordering_args['meta_key'];
		}

		ob_start();

		$products = new WP_Query( apply_filters( 'woocommerce_shortcode_products_query', $args, $atts ) );

		$woocommerce_loop['columns'] = $columns;

		if ( $products->have_posts() ) : ?>

			<?php woocommerce_product_loop_start(); ?>

				<?php while ( $products->have_posts() ) : $products->the_post(); ?>

					<?php wc_get_template_part( 'content', 'min' ); ?>

				<?php endwhile; // end of the loop. ?>

			<?php woocommerce_product_loop_end(); ?>

		<?php endif;

		woocommerce_reset_loop();
		wp_reset_postdata();

		return '<div class="woocommerce columns-' . $columns . '">' . ob_get_clean() . '</div>';
	}
	add_shortcode('wc_product_cat', 'wc_product_category');